package com.zensun.web.controller.monitor;

import com.zensun.common.annotation.Log;
import com.zensun.common.core.controller.BaseController;
import com.zensun.common.core.domain.R;
import com.zensun.common.core.page.PageDataInfo;
import com.zensun.common.enums.BusinessType;
import com.zensun.system.domain.dto.SysOperLogDto;
import com.zensun.system.domain.vo.SysOperLogVo;
import com.zensun.system.service.ISysOperLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 操作日志记录
 *
 * @author gmk
 */
@Api(value = "操作日志管理", tags = "操作日志模块")
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperlogController extends BaseController {
    @Autowired
    private ISysOperLogService operLogService;

    @ApiOperation("查询操作日志列表")
    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    @GetMapping("/list")
    public R<PageDataInfo<SysOperLogVo>> list(SysOperLogDto operLogDto) {
        startPage();
        return R.success(getPageDataTable(operLogService.list(operLogDto)));
    }

    @ApiOperation("删除操作日志")
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/{operIds}")
    public R remove(@ApiParam("ID集合（1,2）") @PathVariable Long[] operIds) {
        return R.toAjax(operLogService.deleteOperLogByIds(operIds));
    }

    @ApiOperation("清空操作日志")
    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:clear')")
    @DeleteMapping("/clean")
    public R clean() {
        operLogService.cleanOperLog();
        return R.success();
    }
}
